package com.fan.shop.businesslogic;

import org.apache.log4j.Logger;

import com.fan.shop.domain.TransactionReferenceGroup;
import com.fan.shop.global.ShopGlobalVariables;
import com.fan.shop.process.ProcExec;
import com.fan.shop.services.TransactionReferenceGroupService;

public class TransactionReferenceGroupCreateProcess extends ProcExec<Integer> {

	private static Logger logger = Logger
			.getLogger(TransactionReferenceGroupCreateProcess.class);
	private String name;
	private String description;

	private TransactionReferenceGroupService transactionReferenceGroupService;

	private String errorMessage;

	public static Logger getLogger() {
		return logger;
	}

	public static void setLogger(Logger logger) {
		TransactionReferenceGroupCreateProcess.logger = logger;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}


	public TransactionReferenceGroupService getTransactionReferenceGroupService() {
		return transactionReferenceGroupService;
	}

	public void setTransactionReferenceGroupService(
			TransactionReferenceGroupService transactionReferenceGroupService) {
		this.transactionReferenceGroupService = transactionReferenceGroupService;
	}

	public String getErrorMessage() {
		return errorMessage;
	}

	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}

	@Override
	public Integer processImpl() {
		if (transactionReferenceGroupService.hasTransactionReferenceGroup(name)) {
			errorMessage = "Transaction Reference Group with same code already exists!";
			return ShopGlobalVariables.FAILED;
		}

		TransactionReferenceGroup transactionReferenceGroup = new TransactionReferenceGroup();
		transactionReferenceGroup.setName(name);
		transactionReferenceGroup.setDescription(description);

		transactionReferenceGroupService
				.addTransactionReferenceGroup(transactionReferenceGroup);

		return ShopGlobalVariables.SUCCESS;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
